package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.utils.IdUtils;
import com.lw.sbdemo2.common.utils.ValidUtil;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.web.anno.ResultController;
import com.lw.sbdemo2.entity.TkErrorType;
import com.lw.sbdemo2.entity.TkUserErrorExamDetail;
import com.lw.sbdemo2.mapper.TkUserErrorExamDetailMapper;
import com.lw.sbdemo2.service.TkUserErrorExamDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;

/**
 * <p>标题: 用户错题细表服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-4-14
 */
@ResultController
@Api(description = "TkUserErrorExamDetailController", tags = {"用户错题细表服务"})
@RequestMapping(value = "/tkUserErrorExamDetail")
public class TkUserErrorExamDetailController extends BaseController {

    /**
     * 用户错题细表服务
     */
    @Autowired
    private TkUserErrorExamDetailService tkUserErrorExamDetailService;

    /**
     * 用户错题细表服务
     */
    @Autowired
    private TkUserErrorExamDetailMapper tkUserErrorExamDetailMapper;

    @ApiOperation(value = "获取用户错题细表列表")
    @GetMapping("")
    public List<TkUserErrorExamDetail> findList(TkUserErrorExamDetail tkUserErrorExamDetail) {
        return tkUserErrorExamDetailService.findList(tkUserErrorExamDetail);
    }

    @ApiOperation(value = "获取班级准确率")
    @GetMapping("/getClassExtract")
    public HashMap<Object, Object> getClassExtract(TkUserErrorExamDetail tkUserErrorExamDetail) throws Exception {
        return tkUserErrorExamDetailService.getClassExtract(tkUserErrorExamDetail);
    }

    @ApiOperation(value = "获取用户错题类别")
    @GetMapping("/getTkTypeNum")
    public List<TkErrorType> getTkTypeNum(String userId) {
        return tkUserErrorExamDetailMapper.getTkTypeNum(userId);
    }

    @ApiOperation(value = "获取用户错题细表列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkUserErrorExamDetail> page(String query, @Required("pageNum") PageInfo pageInfo, TkUserErrorExamDetail tkUserErrorExamDetail) {
        return tkUserErrorExamDetailService.findListPage(query, pageInfo, tkUserErrorExamDetail);
    }

    @ApiOperation(value = "获取用户错题细表详细信息", notes = "根据url的id来获取用户错题细表详细信息")
    @ApiImplicitParam(name = "id", value = "用户错题细表ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkUserErrorExamDetail get(@PathVariable String id) {
        return tkUserErrorExamDetailService.getById(id);
    }

    @ApiOperation(value = "创建用户错题细表")
    @PostMapping("/insert")
    public void insert(TkUserErrorExamDetail tkUserErrorExamDetail) {
        tkUserErrorExamDetail.setHandleFlag("1");
        tkUserErrorExamDetail.setQuestionId(IdUtils.uuid());
        tkUserErrorExamDetailService.insert(tkUserErrorExamDetail);
    }

    @ApiOperation(value = "更新用户错题细表详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户错题细表ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkUserErrorExamDetail tkUserErrorExamDetail) {
        tkUserErrorExamDetailService.update(tkUserErrorExamDetail);
    }

    @ApiOperation(value = "删除用户错题细表", notes = "删除用户错题细表")
    @ApiImplicitParam(name = "id", value = "用户错题细表ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkUserErrorExamDetail(TkUserErrorExamDetail tkUserErrorExamDetail) {
        if (ValidUtil.isEmptyOrNull(tkUserErrorExamDetail.getQuestionId())) {
            tkUserErrorExamDetailMapper.deleteExamTypeAll(tkUserErrorExamDetail);
        } else {
            tkUserErrorExamDetailService.delete(tkUserErrorExamDetail);
        }
    }

    @ApiOperation(value = "更新用户错题细表", notes = "删除用户错题细表")
    @ApiImplicitParam(name = "id", value = "用户错题细表ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/updateD")
    public void updateD(TkUserErrorExamDetail tkUserErrorExamDetail) {
        if (ValidUtil.isEmptyOrNull(tkUserErrorExamDetail.getQuestionId())) {
            tkUserErrorExamDetailMapper.updateExamTypeAll(tkUserErrorExamDetail);
        } else {
            tkUserErrorExamDetailMapper.updateQue(tkUserErrorExamDetail);
        }
    }

}
